﻿#region Copyright
/* Product of DTL Software
 * Product Name : Support Memmory
 * Author : dinhtienlam.spkt@gmail.com
 * About: Developer of DTL Software
 * Contact : 0966 330 237
 */
#endregion

#region Using default
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design; 
#endregion

namespace Lamdt.Controls
{
    public enum ButtonColor
    {
        None,
        DarkBlue,
        LightBlue
    }

    [Designer(typeof(ControlDesigner))]
    public partial class LamdtButtonCommon : Button
    {
        public LamdtButtonCommon()
        {
            CustomButton();
        }


        private ButtonColor _coStyle = ButtonColor.None;

        [Category("Appearance")]
        [DefaultValue(ButtonColor.None)]
        public ButtonColor Style
        {
            get
            {
                return _coStyle;
            }
            set
            {
                _coStyle = value;
                if (value == ButtonColor.DarkBlue ||
                    value == ButtonColor.None)
                {
                    this.BackgroundImage = global::Lamdt.Controls.Resource.bgButton_Dark;
                    this.ForeColor = System.Drawing.Color.White;
                }
                else
                {
                    this.BackgroundImage = global::Lamdt.Controls.Resource.bgButton_Light;
                    this.ForeColor = Constants.LamdtColor.DarkForeColor;
                }
            }
        }

        private void CustomButton()
        {
            this.FlatAppearance.BorderSize = 0;
            base.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        }

        private ImageLayout _backgroundImageLayout = ImageLayout.Stretch;
        [Browsable(false)]
        [DefaultValue(typeof(ImageLayout), "Stretch")]
        public override ImageLayout BackgroundImageLayout
        {
            set
            {
                base.BackgroundImageLayout = value;
            }
            get
            {
                return _backgroundImageLayout;
            }
        }

        private static Image bgiDarkDefault = global::Lamdt.Controls.Resource.bgButton_Dark;
        private static Image bgiLightDefaultt = global::Lamdt.Controls.Resource.bgButton_Light;
        private static Image bgiDisableDefault = global::Lamdt.Controls.Resource.bgButton_Disable;
        private Image _backgroundImage = bgiDarkDefault;
        [Browsable(false)]
        public override Image BackgroundImage
        {
            set
            {
                base.BackgroundImage = BackgroundImage;
            }
            get
            {
                if (Enabled)
                    if (Style == ButtonColor.DarkBlue ||
                        Style == ButtonColor.None)
                    {
                        return bgiDarkDefault;
                    }
                    else
                    {
                        return bgiLightDefaultt;
                    }
                else
                    return bgiDisableDefault;
            }
        }

        public bool ShouldSerializeBackgroundImage()
        {
            return false;
        }

        public void ResetBackgroundImage()
        {
        }

        [Browsable(false)]
        [DefaultValue(typeof(FlatStyle), "Flat")]
        public FlatStyle dtlFlatStyle
        {
            set {}
            get
            {
                return base.FlatStyle;
            }
        }

        private static Font _fontDefault =
            new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
        private Font _font = _fontDefault;
        public override Font Font
        {
            get
            {
                return _font;
            }
            set
            {
                base.Font = value;
                _font = value;
            }
        }

        public bool ShouldSerializeFont()
        {
            return Font != _fontDefault;
        }

        public override void ResetFont()
        {
            Font = _fontDefault;
        }

        private Cursor _cursor = Cursors.Hand;
        [Category("Appearance")]
        [DefaultValue(typeof(Cursor), "Hand")]
        public override Cursor Cursor
        {
            set
            {
                _cursor = value;
                base.Cursor = value;
            }
            get
            {
                return _cursor;
            }
        }

        [Browsable(false)]
        public override Color ForeColor
        {
            get
            {
                if (Style == ButtonColor.DarkBlue ||
                    Style == ButtonColor.None)
                {
                    return System.Drawing.Color.White;
                }
                else
                {
                    return Constants.LamdtColor.DarkForeColor;
                }
            }
        }

        public bool ShouldSerializeForeColor()
        {
            if (Style == ButtonColor.None ||
                Style == ButtonColor.DarkBlue)
            {
                if (ForeColor == Color.White)
                    return false;
            }
            else
            {
                if (ForeColor == Constants.LamdtColor.DarkForeColor)
                    return false;
            }
            return true;
        }

        public override void ResetForeColor()
        {
            if (Style == ButtonColor.None ||
                Style == ButtonColor.DarkBlue)
            {
                ForeColor = Color.White;
            }
            else
            {
                ForeColor = Constants.LamdtColor.DarkForeColor;
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.ResumeLayout(false);

        }
    }
}
